package com.koron.css2.newProjectCenter.callback;

import com.alibaba.fastjson.JSONObject;
import com.koron.css2.newProjectCenter.bean.PjInfoBean;
import com.koron.css2.newProjectCenter.mapper.PjInfoMapper;
import com.koron.css2.newProjectCenter.service.PjInfoService;
import com.koron.css2.newProjectCenter.vo.gcjs.GJResponseData;
import com.koron.css2.serviceManage.bean.UserInfoBean;
import com.koron.util.Constant;
import com.koron.util.HttpUtil;
import com.koron.util.secret.StaticInfo;
import org.koron.ebs.mybatis.SessionFactory;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Service;
import org.swan.bean.MessageBean;

import static com.koron.css2.newProjectCenter.service.gcjsData.ZjAcceptanceInfo;

/**
 * 合同签约节点回调
 */
@Service(PjInfoService.CONTRACT_SIGN)
public class ContractSignCallback implements IPjInfoNodeCallback{

    private static Logger logger = LoggerFactory.getLogger(ContractSignCallback.class);

    @Override
    public MessageBean callback(SessionFactory factory, PjInfoBean pjInfoBean, UserInfoBean userInfo) {
        try {
            if  (GCJS_COMPANY.equals(userInfo.getCurWaterCode()) && pjInfoBean.getGcjsStatic() == 2) {
                PjInfoMapper pjInfoMapper = factory.getMapper(PjInfoMapper.class);
                //修改工建受理状态
                pjInfoMapper.updateGcjsStaticById(pjInfoBean.getId(), 3);
                JSONObject jsonObject = ZjAcceptanceInfo(null, "2", pjInfoBean, userInfo, factory);
                logger.info("报装审批数据推送至工建参数：" + jsonObject.toJSONString());
                String s = HttpUtil.sendPost(StaticInfo.interBusiApi + "/gcjs/statusUpdateReception", jsonObject.toJSONString());
                GJResponseData responseData = com.koron.util.JsonUtils.jsonToPojo(s, GJResponseData.class);
                if (responseData.getErrcode() != GJResponseData.SUCCESS_CODE) {
                    logger.error("审批推送承办状态至工建失败,"+responseData.getMessage());
                }
            }
        }catch (Exception e){
            logger.error("审批推送承办状态至工建失败", e);
        }
        return MessageBean.create(Constant.MESSAGE_INT_SUCCESS, "success", Void.class);
    }
}
